"""Definition of the discount content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata
from Products.ATContentTypes.content.newsitem import ATNewsItem,ATNewsItemSchema

# -*- Message Factory Imported Here -*-
from my315ok.xtinfocontent import xtinfocontentMessageFactory as _

from my315ok.xtinfocontent.interfaces import Idiscount
from my315ok.xtinfocontent.config import PROJECTNAME

discountSchema = ATNewsItemSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

    atapi.TextField(
        'text',
        storage=atapi.AnnotationStorage(),
        default_output_type = 'text/html',
        widget=atapi.RichWidget(
            label=_(u"introduction"),
            description=_(u""),
        ),
        required=True,
    ),


    atapi.ImageField(
        'photo',
        storage=atapi.AnnotationStorage(),
        widget=atapi.ImageWidget(
            label=_(u"promotive photo"),
            description=_(u""),
        ),
        validators=('isNonEmptyFile'),
    ),


))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

discountSchema['title'].storage = atapi.AnnotationStorage()
discountSchema['description'].storage = atapi.AnnotationStorage()
discountSchema['photo'].widget.visible = 0
discountSchema['text'].widget.visible = 1
discountSchema['imageCaption'].widget.visible = 0

schemata.finalizeATCTSchema(discountSchema, moveDiscussion=False)


class discount(ATNewsItem):
    """make a discount for sales"""
    implements(Idiscount)

    meta_type = "discount"
    schema = discountSchema
    _at_rename_after_creation = True

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    text = atapi.ATFieldProperty('text')

    photo = atapi.ATFieldProperty('photo')


atapi.registerType(discount, PROJECTNAME)
